package com.longkey.workflow.client.canvas
{
	import com.longkey.workflow.client.constants.AnchorType;
	import com.longkey.workflow.client.constants.ElementType;
	import com.longkey.workflow.client.constants.StatusType;
	import com.longkey.workflow.client.property.IPropEditableElement;
	import com.longkey.workflow.client.util.IDGenerator;
	
	import flash.ui.MouseCursor;
	
	import mx.managers.CursorManager;
	import mx.utils.UIDUtil;
	
	import spark.components.supportClasses.SkinnableComponent;
	
	public class BaseElement extends SkinnableComponent implements IPropEditableElement
	{
		public var status:int = StatusType.NOP;
		public var anchor:int = AnchorType.NOP;
		public var type:int = ElementType.NOP;
		public var cursor:String = MouseCursor.AUTO;
		
		protected var canvas:WFCanvas;
		
		public function BaseElement(elementType:int = ElementType.NOP)
		{
			super();
			this.name = "";
			this.type = elementType;
			this.id = IDGenerator.UUID();
			var skinClass:Class = null;
			switch(this.type){
				case ElementType.START:
					this.width = 36;
					this.height = 36;
					this.explicitMinWidth = 30;
					this.explicitMinHeight = 30;
					skinClass = com.longkey.workflow.client.canvas.NodeStartSkin;
					break;
				case ElementType.END:
					this.width = 36;
					this.height = 36;
					this.explicitMinWidth = 30;
					this.explicitMinHeight = 30;
					skinClass = com.longkey.workflow.client.canvas.NodeEndSkin;
					break;
				case ElementType.TASK:
					this.width = 90;
					this.height = 46;
					this.explicitMinHeight = 30;
					this.explicitMinWidth = 60;
					skinClass = com.longkey.workflow.client.canvas.NodeTaskSkin;
					break;
				case ElementType.PROC:
					this.width = 90;
					this.height = 46;
					this.explicitMinHeight = 30;
					this.explicitMinWidth = 60;
					skinClass = com.longkey.workflow.client.canvas.NodeProcSkin;
					break;
				case ElementType.LINK:
//					this.depth = 4;
					skinClass = com.longkey.workflow.client.canvas.FlowLinkSkin;
					break;
				default:
					break;
			}
			
			if(skinClass != null){
				this.setStyle("skinClass", skinClass);
			}
			init();
		}
		
		public function get selected():Boolean{
			return false;
		}
		
		public function refresh():void{
			switch(this.type){
				case ElementType.START:
				case ElementType.END:
					if(this.width < 30)
						this.width = 30;
					this.height = this.width;
					break;
				case ElementType.TASK:
				case ElementType.PROC:
					if(this.width < 60)
						this.width = 60;
					if(this.height < 30)
						this.height = 30;
					break;
				default:
					break;
			}
		}
		
		protected function init():void{
			
		}

		public function setParent(canvas:WFCanvas):void{
			this.canvas = canvas;
			this.name = canvas.getDefaultElementName(this.type);
		}
		
		[Bindable]
		public function get label():String{
			return this.name;
		}
		
		public function set label(label:String):void{
			this.name = label;
		}
		
		public function get elementKey():String
		{
			return this.id;
		}
		
		public function set elementKey(eleKey:String):void
		{
			this.id = eleKey;
		}
		
		public function get elementName():String
		{
			return this.label;
		}
		
		public function set elementName(eleName:String):void
		{
			this.label = eleName;
		}
		
		public function get props():Array
		{
			// TODO Auto Generated method stub
			return null;
		}
		
		
	}
}